<template>
  <div>
    <el-card shadow="always" :body-style="{ padding: '20px' }">
      <el-form
        :model="cForm"
        ref="form"
        label-width="80px"
        :inline="false"
        size="normal"
      >
        <el-select
          v-model="cForm.gradeid"
          placeholder="小学"
          clearable
          filterable
          @change="getgradeid(cForm.gradeid)"
        >
          <el-option
            v-for="item in getreqgetclassdata"
            :key="item.id"
            :label="item.grade"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form>
    </el-card>

    <el-card shadow="always" :body-style="{ padding: '20px' }">
      <el-table :data="classdata" border stripe>
        <el-table-column type="index" label="序号" :width="80">
        </el-table-column>
        <el-table-column prop="" label="课程" :width="80">
          <template slot-scope="{ row, $index }">
            <div>
              {{ row.class }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="内容一" width="width">
          <template slot-scope="{ row, $index }">
            <div>
              {{ row.content_0 }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="内容二" width="width">
          <template slot-scope="{ row, $index }">
            <div>
              {{ row.content_1 }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="内容三" width="width">
          <template slot-scope="{ row, $index }">
            <div>
              {{ row.content_2 }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="prop" label="操作" width="width">
          <template slot-scope="{ row, $index }">
            <div>
              <el-button
                type="success"
                size="mini"
                icon="el-icon-sort-up"
                @click="updatashop(row)"
                circle
              ></el-button>

              <el-button
                type="warning"
                size="mini"
                circle
                icon="el-icon-edit"
                @click="showshopdetail(row)"
              ></el-button>

              <el-button
                type="info"
                size="mini"
                circle
                icon="el-icon-info"
                @click="maintenance(row)"
              ></el-button>
              <el-button
                type="danger"
                size="mini"
                circle
                @click="deletebutton(row)"
                icon="el-icon-delete"
              >
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 抽屉数据 -->
    <el-drawer
      style="font-size: 30px; color: #000"
      title="编辑文章"
      :visible.sync="drawer"
      :direction="direction"
      size="50%"
      :before-close="handleClose"
    >
      <!-- 名称 -->
      <el-row>
        <el-col :span="5">科目:</el-col>
        <el-col :span="16">{{classname}}
        </el-col>
      </el-row>
      <!-- //描述 -->
      <el-row>
        <el-col :span="10">文章内容1:</el-col>
      </el-row>
      <el-row>
        <el-input
            type="textarea"
            :rows="6"
            placeholder="请输入内容"
            v-model="cForm.content_0"
          >
          </el-input>
      </el-row>
      <!-- 价格 -->
      <el-row>
        <el-col :span="10">文章内容2:</el-col>
      </el-row>
      <el-row >
        <el-input
            type="textarea"
            :rows="6"
            placeholder="请输入内容"
            v-model="cForm.content_1"
          >
          </el-input>
      </el-row>
      <el-row>
        <el-col :span="10">文章内容3:</el-col>
      </el-row>
      <el-row >
        <el-input
            type="textarea"
            :rows="6"
            placeholder="请输入内容"
            v-model="cForm.content_2"
          >
          </el-input>
      </el-row>
      <el-row>
        <el-button style="display: flex;justify-content: center;" type="success" size="default" @click="editcontentapi(done)">保存</el-button>
      </el-row>
      
      
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: "",

  data() {
    return {
      classdata: [],
      getreqgetclassdata: [],
      drawer: false,
      direction: "rtl", //抽屉格式
      gradename: "小学",
      classname:"",
      cForm: {
        id:0,
        gradeid: "",
        content_0: "",
        content_1: "",
        content_2: "",
      },
    };
  },
  methods: {
    async getdata(classname) {
      let result = await this.$API.text.reqclassdata(classname);
      if (result.code === 200) {
        this.classdata = result.data.detail_grade;
        this.getreqgetclassdata = result.data.grade;
      }
    },
    getgradeid(name) {
      this.getdata(this.getreqgetclassdata[name].grade);
    },
    async updatashop(row) {},
    //点击修改赋值内容:
    async showshopdetail(row) {
      this.cForm.content_0 = row.content_0;
      this.cForm.content_1 = row.content_1;
      this.cForm.content_2 = row.content_2;
      this.cForm.id = row.id;
      this.classname = row.class;
      console.log(row);
      this.drawer = true;
    },
    //info按钮
    maintenance(row) {
      this.$message("开发维护中...");
    },
    async deletebutton(eow) {
      this.$message({
        type:"error",
        message:"不可删除"
      });
    },
    //关闭抽屉:
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    //发起修改请求
    async editcontentapi(){
      let result = await this.$API.text.editdetail_grade(this.cForm);
      if(result.code === 200){
        this.$message({
           type:"success",
           message:`${result.data.message}`
        });
      }
    }
  },
  mounted() {
    this.getdata(this.gradename);
  },
};
</script>

<style scoped></style>
